import React,{Component} from 'react'
import {View,Text,Alert} from 'react-native'
import {showShort} from '../../util/Toast'

class Main extends Component{



    componentWillMount() {
        console.log('componentWillMount')
        this._validateLogin()
    }

    componentDidMount() {
        console.log('componentDidMount')
    }

    componentDidUpdate(){
        console.log('componentDidUpdate')

    }


    componentWillUnmount() {
        console.log('componentWillUnmount')
    }




    //TODO 判断是否登录 从redux中读取token
    _validateLogin(){
        const {navigate} = this.props.navigation
        if(this.props.loginToken){
            return
        }else {
            showShort("请先登录!")
            navigate('Login')
        }

        //
        // let option = {
        //     cancelable: true,
        //     onDismiss : false,
        // }
        // let cancle = {
        //     text: '取消'
        // }
        // let ok = {
        //     text: '登录',
        //     onPress: ()=>{
        //         navigate('Login',{parent:1})
        //     }
        // }
        // Alert.alert('提示','还没有登录哦,去登录',[cancle,ok],option,null)
    }


    render(){
        console.log('render')

        // const {navigation} = this.props
        // const itemId = navigation.getParam('itemId');
        // if(itemId){
        //     console.log('收到了itemId:'+itemId)
        // }







        return (

            <View>
                <Text>this is welcome page</Text>
            </View>

        )
    }

}


export default Main

